package com.glela.serial.service.impl;

import com.glela.serial.mapper.DiscoveryTypeMapper;
import com.glela.serial.model.DiscoveryType;
import com.glela.serial.model.DiscoveryTypeFZVo;
import com.glela.serial.service.DiscoveryTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service("discoveryTypeService")
public class DiscoveryTypeServiceImpl implements DiscoveryTypeService {
	private static Logger logger = LoggerFactory.getLogger(DiscoveryTypeServiceImpl.class);
	
	@Autowired
	private DiscoveryTypeMapper discoveryTypeMapper;
	
	
	
	@Override
	public List<DiscoveryType> selectAllDiscoveryType() {
		logger.info("begin------selectAllDiscoveryType-------impl");
		return discoveryTypeMapper.queryAll();
	}

	@Override
	public List<DiscoveryTypeFZVo> selectAllDiscoveryTypeNew() {
		List<DiscoveryType> discoveryTypes = discoveryTypeMapper.queryAllOrderBy();
		List<DiscoveryTypeFZVo>  discoveryList = new ArrayList<>();
		DiscoveryTypeFZVo discoveryTypeFZVo = null;
		for (DiscoveryType discoveryType : discoveryTypes) {//封装为父子层级的数据格式
			if (discoveryType.getDiscoveryTypeParent() == 0) {
				discoveryTypeFZVo = new DiscoveryTypeFZVo();//父
				discoveryTypeFZVo.setId(discoveryType.getId());
				discoveryTypeFZVo.setDiscoveryType(discoveryType.getDiscoveryType());
				discoveryTypeFZVo.setDiscoveryTypeParent(discoveryType.getDiscoveryTypeParent());
				discoveryTypeFZVo.setTypeName(discoveryType.getTypeName());
				discoveryTypeFZVo.setExtends1(discoveryType.getExtends1());
				//查找所属的子发现
				for (DiscoveryType discovery : discoveryTypes) {
					if (Integer.parseInt(discovery.getDiscoveryTypeParent().toString()) == discoveryType.getId()) {
						discoveryTypeFZVo.getDiscoveryTypeList().add(discovery);
					}
				}
				discoveryList.add(discoveryTypeFZVo);
			}
		}
		return discoveryList;
	}

}
